<?php
class AutoController extends AppController{
	var $uses = array('User','FollowUser','TweetBox','Tweet');
	function autoUser(){
		$this->autoRender = false;
		$arrRanDomFName = array('Huy','Cuong','Manh');
		$arrRanDomLName = array('Nguyen','Dao','Le');
		$arrRanDomTweet = array('huy','en','ta','voi','coi','sinh');
		$arrRanDomPass = array('huy','en','ta','voi','coi','sinh');
//		$arrRanDomMediaUrl = array( 'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-1.jpg',
//								    'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-3.jpg',
//									'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-4.jpg',
//									'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-5.jpg',
//									'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-6.jpg',
//									'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-7.jpg',
//									'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-8.jpg',
//									'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-14.jpg',
//									'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-15.jpg',
//									'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-13.jpg',
//									'http://img-hn.24hstatic.com:8008/upload/3-2012/images/2012-08-30/1346303245-a-khoi-hong-anh-10.jpg');

		
		$arrRanDomMediaUrl = array( 'http://seablogs.zenfs.com/u/sbQ9KUeZBRlEfhVgryKYeGo-/profile/tn_1.jpg',
									'http://files.myopera.com/salmondine/albums/16280/Fairy%20Avatar.png',
									'http://www.avatarswizard.com/uploads/av/2009-04/thumbs/100x100_1238675340_pyrenean_mastiff_2.jpg');
		$arrRanDomLocationName = array('Ha Noi','TP HCM','Khanh Hoa','Da Nang','Hai Phong','Thanh Hoa');
		$arrRanDomScreenName = array('Was born in Ha Noi','ハノイから来ました');		
		
//		yield();
		for($i =0;$i<=100000;$i++){
			$arrSave['name'] = "One Of Them".$i;//$arrRanDomFName[rand(0,2)]. " " . $arrRanDomLName[rand(0,2)];
			$arrSave['nick_name'] = "oneofthem".$i;//$arrRanDomUname[rand(0,5)];//.$arrRanDomUname[rand(0,5)];
			$arrSave['password'] = "123456";//$arrRanDomPass[rand(0,5)];
			$arrSave['profile_image_url'] = $arrRanDomMediaUrl[rand(0,2)];
			$arrSave['location_text'] = $arrRanDomLocationName[rand(0,5)];
			$arrSave['screen_name'] = utf8_encode($arrRanDomScreenName[rand(0,1)]);
			$arrSave['email'] = "oneofthem".$i."@oneofthem".$i.".jp";
			$this->User->create();
			$this->User->set($arrSave);
//			if(!$this->User->findByNickName($arrSave['nick_name'])){
				if(!$this->User->save())
					die('cannot insert');
//			}
		}
		echo "Done";
	}
	
	function autoFollow(){
		$this->autoRender = false;
		for ($i=1;$i<=40218;$i++){
			$this->FollowUser->create();
			$this->FollowUser->set(array('user_id'=>(($i-1)%5)+1,
										 'user_id_followed'=>(($i + 5000)%40218)));
			$this->FollowUser->save();
		}
		echo "Done";
	}
	
	function autoTweet(){
		$this->autoRender = false;
		$arrText = "anh co mot thang ban lam o one of them neu em co gi khong hieu thi lien lac voi no nhe no ten la duc nho";
		$arrSite = "googleyahootweetermegafun";
		for ($i = 1;$i<=35273;$i++){
			$uid = rand(1,35273);
			$this->Tweet->create();
			$this->Tweet->set(array('tweet_text'=>substr(str_shuffle($arrText),rand(0,strlen($arrText)),rand(10,30))."@".substr(str_shuffle($arrSite),rand(0,strlen($arrSite)),rand(5,10))." #".substr(str_shuffle($arrSite),rand(0,strlen($arrSite)),rand(5,10))." at Vuon Dao",
									'user_id'=>$uid));
			if($tw = $this->Tweet->save()){
				$uFl = $this->FollowUser->getListFl($uid);
//				debug($tw);die;
				if($uFl){
					foreach ($uFl as $fl){
						$this->TweetBox->create();
						$this->TweetBox->set(array( 'tweet_id'=>$tw['Tweet']['id'],
													'user_id'=>$fl));
						$this->TweetBox->save();
					}
				}
			}
		}
		echo "Done";
	}
	
	function alterTweet(){
		$this->autoRender = false;
		$this->Tweet->unbindModel(array('hasMany'=>array('TweetBox','TweetTag','TweetMention','TweetUrl','TweetFavorite')),false);
		$this->Tweet->updateAll(array('Tweet.tweet_text'=>"'we are @one of them #20120818'"), array('Tweet.id >=' =>1));
	}
}